package com.yoo.ons.dialog

import android.app.Activity
import android.view.View
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.gyf.immersionbar.ImmersionBar
import com.yoo.chat.kit.utils.AnimatorUtils
import com.yoo.module_base.utils.setOnClickCallback
import com.yoo.ons.R
import com.yoo.ons.adapter.StringPureAdapter
import razerdp.basepopup.BasePopupWindow

class UserActionPopup (var ctx: Activity, var targetId: String,var listener:UserActionListener ) :  BasePopupWindow(ctx) {
    private val reportTextList= arrayListOf(ctx.getString(com.yoo.module_res.R.string.report_one),ctx.getString(com.yoo.module_res.R.string.report_two),ctx.getString(com.yoo.module_res.R.string.report_three),ctx.getString(com.yoo.module_res.R.string.report_four),ctx.getString(com.yoo.module_res.R.string.report_five),ctx.getString(com.yoo.module_res.R.string.report_six),ctx.getString(com.yoo.module_res.R.string.report_seven))

    init {
        setContentView(R.layout.popup_user_action)
        initView()
        showAnimation = AnimatorUtils.popupWindowShow()
        dismissAnimation= AnimatorUtils.popupWindowDismiss()
    }

    private fun initView() {
        val outsideContainer = findViewById<View>(R.id.outside_container)
        val lineTop = findViewById<View>(R.id.line_top)
        val dialogCancel = findViewById<TextView>(R.id.dialog_cancel)

        val dialogReport = findViewById<TextView>(R.id.dialog_report)
        val dialogBlock = findViewById<TextView>(R.id.dialog_block)
        val reportList = findViewById<RecyclerView>(R.id.report_list)
        dialogReport.setOnClickCallback {//点击举报展示列表
            lineTop.isVisible=false
            dialogReport.isVisible=false
            dialogBlock.isVisible=false
            reportList.isVisible=true
        }
        val stringPureAdapter = StringPureAdapter()
        stringPureAdapter.addAll(reportTextList)
        reportList.layoutManager= LinearLayoutManager(ctx)
        reportList.adapter=stringPureAdapter
        stringPureAdapter.setListener {
            listener.userReport(it)
            dismiss()
        }
        outsideContainer.setOnClickCallback {
            dismiss()
        }

        dialogCancel.setOnClickCallback {//点击取消先判断举报列表是否展示，展示的话返回到举报拉黑，否则关闭
            if (reportList.isVisible){
                lineTop.isVisible=true
                dialogReport.isVisible=true
                dialogBlock.isVisible=true
                reportList.isVisible=false
                return@setOnClickCallback
            }
            dismiss()
        }


        dialogBlock.setOnClickCallback {
            listener.userBlack()
            dismiss()
        }
        onDismissListener =object : OnDismissListener() {
            override fun onDismiss() {
                ImmersionBar.with(ctx,true)
                    .navigationBarEnable(false)
                    .init()
            }

        }
        setOutSideDismiss(true)
        isOutSideTouchable = true
        ImmersionBar.with(ctx,true)
            .navigationBarColor("#AA089A")
            .navigationBarEnable(true)
            .init()
    }

    interface UserActionListener{
        fun userReport(reason:String)
        fun userBlack()
    }
}